#include<iostream>
#include<algorithm>
using namespace std;
int n = 0, pre[100000], mid[100000];
int FindNode(int num, int start, int end) {
    for (int _ = start; _ <= end; _++) {
        if (mid[_] == num) return _;
    }
    return -1;
}
void CreatTree(int &cur_pos, int l , int r) {
    // current postion greater than all node length or left postion greater than right postion
    if (cur_pos > n - 1 || l > r) { 
        if (l > r) cur_pos -= 1;
        return;
    }

    if (l == r) {
        // find the root node
        cout << pre[cur_pos] << " "; 
        return; 
    }
    int val = pre[cur_pos];
    int pos = FindNode(val, l, r);
    cur_pos += 1;
    CreatTree(cur_pos, l, pos - 1);
    cur_pos += 1;
    CreatTree(cur_pos, pos + 1, r);
    cout << val << " ";
    return;
}
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> pre[i];
    for (int i = 0; i < n; i++) cin >> mid[i];
    int cur_pos = 0;
    CreatTree(cur_pos, 0, n - 1);
    return 0;
}